WEBVTT

00:01.020 --> 00:06.360
In the last video she worked with rolling such as Six and all of our calculations were based on fixed

00:06.360 --> 00:08.350
size rolling windows.

00:08.400 --> 00:16.200
So for instance when we calculated the simple moving average 50 for the S&amp;P 500 at each point in time

00:16.230 --> 00:21.140
we included the last 50 observations and to our mean calculations.

00:21.150 --> 00:26.760
So the last 50 observations does not necessarily mean the last 50 calendar days.

00:26.880 --> 00:32.910
And as you might know in finance we typically have no trading prices on bank holidays and weekends and

00:32.910 --> 00:39.120
therefore having a fixed size window of 50 means that we are probably looking back more than 50 calendar

00:39.120 --> 00:44.790
days to get the last 50 observations and the last the 50 year trading prices.

00:44.850 --> 00:51.870
So let's have a look in an example and we are still imported the Apple Boeing data frame and let's have

00:51.870 --> 01:01.010
a look at the first seven rows so you may have to stock prices for Apple and Boeing starting with the

01:01.040 --> 01:07.970
thirty first of December 2009 and already here we can see that we have not on each and every calendar

01:07.970 --> 01:10.100
day a trading price.

01:10.100 --> 01:16.400
We have no trading price on the first of January because this is a bank holiday and we also have no

01:16.400 --> 01:24.530
trading prices on the 2nd and 3rd of January because these this Saturday and Sunday and the next trading

01:24.530 --> 01:32.560
price we can observe on the 4th of January and then also here the 9th and the 10th of January.

01:32.700 --> 01:35.990
Also again Saturday and Sunday.

01:35.990 --> 01:41.300
And let's assume that you want to calculate the simple moving average with a window of 3.

01:41.390 --> 01:47.320
Then we can pass uh the integer 3 to the window parameter and we change the mean method.

01:47.330 --> 01:48.260
So let's have a look here.

01:50.550 --> 01:55.410
So it's no surprise that on the first two timestamps we have any invalid use.

01:55.410 --> 02:01.860
And then starting with the third timestamp we actually F on each timestamp the mean stock price for

02:01.860 --> 02:05.780
these three immediately preceding observations.

02:05.850 --> 02:13.520
So he on the 5th of January we have the stock prices on the thirty first the 4th and the 5th and if

02:13.530 --> 02:13.740
year.

02:13.740 --> 02:16.850
The average actually saw pennies simply takes a year.

02:16.860 --> 02:23.220
The last the three observations and obviously this does not mean that these are the last three calendar

02:23.220 --> 02:29.160
days and actually penned US ignores at the time increments between those observations.

02:29.160 --> 02:30.550
So here we are four days.

02:30.570 --> 02:32.210
And here we have only one day.

02:32.250 --> 02:39.030
However we can change this behavior by passing a fixed size time offset rather than a fixed number of

02:39.030 --> 02:41.520
observations through the window parameter.

02:41.880 --> 02:49.340
So let's again have a look at the first seven observations and let's assume that you want to calculate

02:49.370 --> 02:56.560
the simple moving average of the last three calendar days and instead of passing near the end that uh

02:56.630 --> 03:04.840
three to the windows per meter is simply passing a fixed time offset and we can do this as a string.

03:04.840 --> 03:06.980
So here we have uh three days.

03:06.980 --> 03:08.710
So this is actually nothing new

03:14.270 --> 03:20.450
and that our very first glance we can see here that uh we do not get any any end values at the beginning

03:20.750 --> 03:24.490
and therefore it might be a good idea to have a look at the documentation.

03:24.500 --> 03:25.660
So let's have a look here.

03:29.160 --> 03:31.640
So here we have the window perimeter.

03:32.030 --> 03:34.740
And here we can define the size of the moving window.

03:34.740 --> 03:39.930
And this is the number of observations used for calculating these statistics.

03:39.930 --> 03:42.890
And each window will be a fixed size.

03:42.900 --> 03:51.080
So this is here the above example we FCA a fixed sized window of three and now comes our new example.

03:51.350 --> 03:57.890
If it's an offset so here three days then this will be the time period of each window and each window

03:57.890 --> 04:03.140
will be a variable size based on the observations included in the time period.

04:03.230 --> 04:06.590
And that's also if I look at the parameter Min periods.

04:06.740 --> 04:11.780
So this is the minimum number of observations and window required to have a value.

04:12.140 --> 04:17.840
And otherwise the result is an A and for a window that is specified by an offset.

04:17.840 --> 04:22.980
So this is our new example here than men periods will default to 1.

04:23.210 --> 04:27.920
Otherwise that means we have a sick fixed sized window of three.

04:28.220 --> 04:33.110
So otherwise men period will default to the size of the window.

04:33.110 --> 04:38.290
So if you pass the fixed size then the main period is by default.

04:38.390 --> 04:44.760
The same as our window here three and therefore we get here at the very first two time stamps and they

04:44.770 --> 04:51.900
end values and by passing a time offset the mean periods parameter the default value is 1.

04:52.010 --> 04:58.570
So on each of the timestamps here we have at least the one value and the last the three calendar days

04:58.580 --> 05:01.790
and therefore we do not have you any missing values.

05:01.940 --> 05:09.090
And of course we could also change this and pass uh also here maybe a three to the min periods per metre

05:09.110 --> 05:09.920
so let's say this

05:15.310 --> 05:23.750
and let's have a look and if we can see that we have a lot of any end values and intuitively we actually

05:23.750 --> 05:29.150
only get on the weekdays uh Wednesday Thursday and Friday.

05:29.170 --> 05:36.350
Well use here because only on these days are the days themselves and the immediately two preceding days

05:36.400 --> 05:44.650
uh weekdays and this is actually quite uncomfortable because we have fear many missing values and uh

05:44.690 --> 05:50.190
therefore pen associate quite clever by changing the default parameter to a one period.

05:50.190 --> 05:58.830
If we are working here with time offsets so working with a fixed size time offset is an additional alternative

05:59.130 --> 06:05.220
how to work with uh rolling statistics and in particular this makes a lot of sense when we are working

06:05.220 --> 06:08.100
with irregular times series.

06:08.370 --> 06:12.900
So we are finishing with this video and I hope to see you also in the next one by.
